home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #11
/
Amiga Plus CD - 2004 - No. 11.iso
/
AmiSoft
/
Util
/
rexx
/
CTGUI.lha
/
CTGUI.rexx
< prev
Wrap
OS/2 REXX Batch file
|
2004-06-22
|
5KB
|
187 lines
/* CTorrent GUI 0.1 (20.06.04)
©2004 Michael Trebilcock */
CTPath = "ctorrent-1.3.2" /* Path to ctorrent-1.3.2 file */
CTArgs = "-C 1" /* CTorrent arguments */
Signal On Break_C
Signal On Halt
Numeric Digits 14
Parse Arg Args
ID=Pragma("ID")
CR="0D"x;TSize="0"
IF Args="" THEN DO
SAY "Usage: RX CTGUI <File>"
SAY "Example: RX CTGUI test.torrent"
Exit
End
IF ~Exists(CTPath) THEN Call Break_C("Cannot find "CTPath,1)
IF Left(Args,1)='"' THEN Args=SubStr(Left(Args,Length(Args)-1),2)
IF ~Exists(Args) THEN Call Break_C("Cannot find "Args,1)
IF Pos(":",Args)>0 THEN Args="/"Translate(Args,"/",":")
ADDRESS COMMAND "SYS:C/RUN >T:CTGUI."ID".tmp "d2c(34)""CTPath""d2c(34) CTArgs d2c(34)""Args""d2c(34)" >PIPE:CTGUI."ID".tmp"
Call Open(IDFile,"T:CTGUI."ID".tmp","R") THEN DO
ProcN=Word(Translate(ReadLn(IDFile),,"]"),2)
Call Close(IDFile)
Call Open(File,"PIPE:CTGUI."ID".tmp","R")
DO UNTIL EOF(File)
Output=ReadLn(File)
Parse Var Output W1" "W2" "W3" "Rest
SELECT
WHEN W1="Piece" THEN PLength=W3
WHEN Output="FILES INFO" THEN DO
Output=ReadLn(File)
IF Word(Output,1)="Directory:" THEN TFile=SubStr(Output,12)
DO UNTIL Word(Output,1)="Total:"
Words=Words(Output)
Word=Word(Output,Words)
IF Word(Output,1)="<1>"&TFile="TFILE" THEN TFile=SubStr(Left(Output,Length(Output)-Length(Word)-1),6)
IF Left(Word,1)="["&Right(Word,1)="]" THEN TSize=TSize+Translate(Word,,"[]")
Output=ReadLn(File)
End
Call GUI()
Call ReadLn(File)
IF ReadCh(File,1)=CR THEN DO
Call Time(R)
DO UNTIL Char=d2c(32)
Line=""
Call ReadCh(File,13)
DO UNTIL Char=CR|Char=d2c(32)
Char=ReadCh(File,1)
Line=Line""Char
End
Line2=Left(Line,Length(Line)-1)
Parse Var Line2 Count"/"Total
IF Count="0" THEN Count="1"
Calc=Time(E)*(Total/Count)-Time(E)
Parse Var Calc Secs"."Rest
Call ToPipe('ID 18 gt="Checksumming... 'Secs's"')
IF ~Exists("T:CTGUI."ID".tmp") THEN Call Break_C()
End
End
End
WHEN W1="Listen" THEN DO
Char=ReadCh(File,1)
IF Char~=CR THEN DO
DO UNTIL ReadLn(File)=""
End
Char=ReadCh(File,1)
End
Call Time(R)
DO UNTIL EOF(File)
Call ReadCh(File,76)
Line=""
DO UNTIL Pos(" ",Line)>0
Line=Line""ReadCh(File,3)
End
DO UNTIL Char=CR|Char=d2c(10)
Char=ReadCh(File,1)
Line=Line""Char
End
IF Char=d2c(10) THEN DO UNTIL ReadLn(File)=""
End
Parse Var Line Anim" "Clients",["Done"/"Total"/"Avail"],"AvgCPS","AvgUCPS" | "CrtCPS","CrtUCPS" E:"Retries
DSize2=DSize
DSize=Done*PLength
PCent2=PCent
PCent=Done/Total*100
Parse Var PCent PCent"."Rest
IF PCent~=PCent2 THEN Call ToPipe('ID 1 defn='PCent)
Secs=Time(E)
Call ToPipe('ID 7 gt="'Calc()'"')
Call ToPipe('ID 13 gt="'AvgCPS'"')
Call ToPipe('ID 16 gt="'AvgUCPS'"')
IF DSize~=DSize2 THEN DO
IF Done=Total THEN DO
Call ToPipe('ID 18 gt="Download complete"')
Call Delay(300)
Call Break_C()
End
ELSE DO
RSize=TSize-DSize
IF AvgCPS>0 THEN DO
Secs=RSize/AvgCPS
Call ToPipe('ID 10 gt="'Calc()'"')
End
Call ToPipe('ID 18 gt="'DSize'/'TSize'"')
End
End
IF ~Exists("T:CTGUI."ID".tmp") THEN Call Break_C()
End
End
OTHERWISE NOP
End
End
Call Break_C()
Exit
GUI:
IF ~Open(PIPE,"AWNPipe:CTorrent/xc","RW") THEN DO
SAY "Unable to open GUI"
Call Break_C()
End
Call ToPipe('title="CTGUI 0.1 ©2004 Michael Trebilcock" defg v m fw fh width=300')
Call ToPipe('fuelgauge ticks=0 defn=0 percent') /* 1 */
Call ToPipe('layout b=0')
Call ToPipe(' button b=0 ro gt="Title:"')
Call ToPipe(' button b=0 ro gt="'TFile'"') /* 4 */
Call ToPipe('le')
Call ToPipe('layout b=0')
Call ToPipe(' button b=0 ro gt="Elapsed:"')
Call ToPipe(' button b=0 ro gt="00:00:00"') /* 7 */
Call ToPipe('le')
Call ToPipe('layout b=0')
Call ToPipe(' button b=0 ro gt="DL Remaining:"')
Call ToPipe(' button b=0 ro gt="00:00:00"') /* 10 */
Call ToPipe('le')
Call ToPipe('layout b=0')
Call ToPipe(' button b=0 ro gt="Download CPS:"')
Call ToPipe(' button b=0 ro gt="0"') /* 13 */
Call ToPipe('le')
Call ToPipe('layout b=0')
Call ToPipe(' button b=0 ro gt="Upload CPS:"')
Call ToPipe(' button b=0 ro gt="0"') /* 16 */
Call ToPipe('le')
Call ToPipe('layout b=0')
Call ToPipe(' button b=0 ro gt="Checksumming..."') /* 18 */
Call ToPipe('le')
Call ToPipe('open')
Return 0
ToPipe:
Call WriteLn(PIPE,Arg(1))
PIPEOut=ReadLn(PIPE)
Return 0
Calc:
Hour=Secs/3600
Parse Var Hour Hour"."Dec
Dec="0."Dec
Min=Dec*60
Parse Var Min Min"."Dec
Dec="0."Dec
Sec=Dec*60
Parse Var Sec Sec"."Dec
Return Right(Hour,2,0)":"Right(Min,2,0)":"Right(Sec,2,0)
Halt:
Break_C:
IF Arg(2)="1" THEN SAY Arg(1)
Call Close(File)
Call Close(PIPE)
IF ProcN~="PROCN" THEN DO
ADDRESS COMMAND "SYS:C/RUN <>NIL: SYS:C/Break "ProcN
Call Delete("T:CTGUI."ID".tmp")
End
Exit